package com.ruoyi.web.controller.workflow;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.aspectj.weaver.loadtime.Aj;
import org.checkerframework.checker.units.qual.A;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.workflow.domain.CarPackageAudit;
import com.ruoyi.workflow.service.ICarPackageAuditService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 套餐审核Controller
 *
 * @author shier
 * @date 2022-11-17
 */
@RestController
@RequestMapping("/workflow/audit")
public class CarPackageAuditController extends BaseController {

    private final ICarPackageAuditService carPackageAuditService;
    public CarPackageAuditController(ICarPackageAuditService carPackageAuditService) {
        this.carPackageAuditService = carPackageAuditService;
    }

    /** 查询套餐审核列表 */
    @PreAuthorize("@ss.hasPermi('workflow:audit:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarPackageAudit carPackageAudit) {
        startPage();
        List<CarPackageAudit> list = carPackageAuditService.selectCarPackageAuditList(carPackageAudit);
        return getDataTable(list);
    }

    /** 在服务项里发起审核 */
    @PreAuthorize("@ss.hasPermi('workflow:audi:start')")
    @PostMapping("/audit")
    public AjaxResult list(Long id, String info) {
        carPackageAuditService.audit(id, info);
        return AjaxResult.success("审核成功");
    }

    /** 审核功能: 审核通过 OR 不通过 */
    @PostMapping("/doAudit")
    public AjaxResult doAudit(Long id, String taskId, boolean result, String info) {
        carPackageAuditService.doAudit(id, taskId, result, info);
        return AjaxResult.success("审核成功");
    }

    /** 重新发起审核 */
    @PostMapping("/reapply")
    public AjaxResult reapply(Long id, String taskId) {
        carPackageAuditService.reapply(id, taskId);
        return AjaxResult.success("重新发起审核成功");
    }

    /** 查询流程图 */
    /*@PreAuthorize("@ss.hasPermi('workflow:audi:resource')")*/
    @GetMapping("/processing/image")
    public void getProcessingImage(String instanceId, HttpServletResponse resp) throws IOException {
        InputStream in = carPackageAuditService.getProcessingImage(instanceId);
        IOUtils.copy(in, resp.getOutputStream());
    }

    /** 撤销套餐审核 */
    @PreAuthorize("@ss.hasPermi('workflow:audit:cancel')")
    @PostMapping("/cancel")
    public AjaxResult cancel(Long id, String reason) {
        carPackageAuditService.cancel(id, reason);
        return AjaxResult.success("撤销成功!!!");
    }
}
